/*
 *	2004 JAN 24 SHP
 *		1. Added copyright notice
 *		2. Added comments.
 */

using System;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
using FrameworkX.ObjectSpace.Data.Schema;

namespace FrameworkX.ObjectSpace
{
	/// <summary>
	/// A database command container for any object
	/// </summary>
	public class ActionCommand : ICloneable
	{

		/// <summary>
		/// Action Command Constructor
		/// </summary>
		public ActionCommand()
		{
		}

		/// <summary>
		/// Action Command Constructor
		/// </summary>
		/// <param name="command">SQL Database Command </param>
		/// <param name="action">Actions string</param>
		/// <param name="canBeCached">If the database can be cached</param>
		public ActionCommand(IDbCommand command, string action, bool canBeCached)
		{
			this.Command = command;
			this.Action = action;
			this.CanBeCached = canBeCached;
		}

		private bool _canBeCached = false;

		/// <summary>
		/// Indicates if the command can be cached
		/// </summary>
		public bool CanBeCached
		{
			get
			{
				return _canBeCached;
			}
			set
			{
				_canBeCached = value;
			}
		}

		private string _action = "";

		/// <summary>
		/// Action key object
		/// </summary>
		public string Action 
		{
			get
			{
				return _action;
			}
			set
			{
				_action = value;
			}
		}

		private IDbCommand _command = null;

		/// <summary>
		/// The Database command object 
		/// </summary>
		public IDbCommand Command
		{
			get
			{
				return _command;
			}
			set
			{
				_command = value;
			}
		}

		public ActionCommand Clone()
		{
			ActionCommand actionCommand = new ActionCommand ();
			ICloneable command = (ICloneable) this.Command;
			IDbCommand cmd = (IDbCommand) command.Clone();
			cmd.Connection = (IDbConnection) ((ICloneable) this.Command.Connection).Clone();
			actionCommand.Command = cmd;
			actionCommand.Action = this.Action;
			actionCommand.CanBeCached = this.CanBeCached;
			return actionCommand;
		}
		#region ICloneable Members

		object System.ICloneable.Clone()
		{
			return this.Clone();
		}

		#endregion
	}
}
